<%@page import="com.hitrust.gs.business.GSProviderType"%>
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="../../common.jsp"%>
<%@ taglib uri="/page.util.gs.hitrust.com/taglibs/page" prefix="page"%>
<html>
<head>
<title>供应商导入</title>
<META http-equiv=Content-Type content="text/html; charset=UTF-8">
<LINK href="<%=root%>/css/caigouxitong.css" type=text/css rel=stylesheet>
<SCRIPT language="JavaScript" src="<%=root%>/js/calendar.js"></SCRIPT>
<SCRIPT language="JavaScript" src="<%=root%>/js/common.js"></SCRIPT>
<SCRIPT language="JavaScript" src="<%=root%>/js/string.js"></SCRIPT>
<%
    String isPlanPrice = "0";
   if(GSBaseConstants.PLANPRICE.equals("true")){
       isPlanPrice = "1";
      }
   session.setAttribute("modify","true");
%>
<script language="JavaScript">
    var counter;
    
    	function load(){
    		<%
    		  String importResult = (String)request.getAttribute("importResult");
    		   if(importResult != null && "1".equals(importResult)){
    		%>
    			alert("导入成功");
    		<%
    		   }
    		   if(importResult != null && !"1".equals(importResult)){
    		%>
    			alert("<%= importResult %>");
    		<%
    		   }
    		  
    		 %>
    	}

        function checkValue(){
            if(document.all.concentricityid.value == null || Trim(document.all.concentricityid.value) == ""){
                alert("请输入产品集中编码");
                return false;
            }
            if(Trim(document.all.concentricityid.value).length!=<%=GSBaseConstants.TEMPORARY_PRODUCT_CONCENTRICITY%>){
                alert("请输入<%=GSBaseConstants.TEMPORARY_PRODUCT_CONCENTRICITY%>位产品集中编码");
                return false;
            }
            if(document.getElementById("sign").value == "1"){
                alert("集中编码不允许重复！");
                return false;
            }
            if(document.all.providerid.value == null || document.all.providerid.value == ""){
                alert("请选择或输入供应商");
                return false;
            }
            if(document.all.providerid.value != null || document.all.providerid.value != ""){
                var op=document.getElementById("oldpid").value;
                var pid=Trim(document.all.providerid.value);
                if(op!=null&&op!=""){
                    var ob=op.split("%");
                    for(var i=0;i<ob.length;i++){
                        if(pid==ob[i]){
                            alert("相同供应商不能供应同一集中编码产品");
                            return false;
                        }
                    }
                }
            }
            if(document.all.manufacturename.value == null || Trim(document.all.manufacturename.value) == ""){
                alert("请输入产品名称");
                return false;
            }
            if(document.all.manuftype1.options[0].selected && document.all.manuftype2.options[0].selected && document.all.manuftype3.options[0].selected){
                alert("请输入产品种类");
                return false;
            }
            if(document.all.quantunit.value == null || Trim(document.all.quantunit.value) == ""){
                alert("请输入产品数量单位");
                return false;
            }
            if(document.all.unitprice.value == null || Trim(document.all.unitprice.value) == ""||parseFloat(document.all.unitprice.value)<=0||isNaN(document.all.unitprice.value)){
                alert("请输入产品单价");
                return false;
            }
            if(document.all.remark.value.length>2000){
                alert("备注长度不能超过2000字符");
                return false;
            }
            return true;
        }
        function process(){
            getprovalue();
            if(checkValue()){
                form1.action = "<%= response.encodeURL(request.getContextPath() + "/A400314.do") %>";
                form1.submit();
            }
        }
        function selectprovider(){
            var url ="<%=response.encodeURL(request.getContextPath() +"/A401103.do")%>";
            var returnv = window.open(url,null," edge: sunken ,center: Yes, help: No, resizable: Yes, status: No,height=580px, scrollbars=yes");
        }
        function getprovalue(){
            var str="";
            var pr1=document.all.pro1.value;
            var pr2=document.all.machinetype.value;
            var pr3=document.all.pro3.value;
            var pr4=document.all.pro4.value;
            var pr5=document.all.pro5.value;
            var pr6=document.all.pro6.value;
            if(pr1!=""){
                str+=document.getElementById("p1").innerText+"："+pr1+"；";
            }
            if(pr2!=""){
                str+=document.getElementById("p2").innerText+"："+pr2+"；";
            }
            if(pr3!=""){
                str+=document.getElementById("p3").innerText+"："+pr3+"；";
            }
            if(pr4!=""){
                str+=document.getElementById("p4").innerText+"："+pr4+"；";
            }
            if(pr5!=""){
                str+=document.getElementById("p5").innerText+"："+pr5+"；";
            }
            if(pr6!=""){
                str+=document.getElementById("p6").innerText+"："+pr6+"；";
            }
            document.all.property.value=str;
        }
        function pricef(obj){
            if(parseFloat(obj.value)<=0||isNaN(obj.value)){
                obj.value="0.0";
            }
        }
        function doUploadProviderBaseFile(actionObj) 
        {
            if(actionObj.parentElement.children(0).value == "") 
            {
                alert("请选择需要导入的文件。");
                return false;
            }
            form1.action = "<%= response.encodeURL(request.getContextPath() + "/A400110.do") %>";
            form1.submit();
        }
         function checkFile(obj){
          var oExten = obj.value.replace(/^.*\.([^\.]*)$/, '$1').toLowerCase();
          if(oExten != 'xls'&&oExten != 'XLS'){
             obj.outerHTML = obj.outerHTML;
             alert("请确认导入文件为Excel文件");
          }
        }
</script>
</head>
<body BGCOLOR="#f2f2f2" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onload="load()">
<br>
<table width="95%" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr>
    <td height="20"> 
      <table width="100%" border="0" cellspacing="0" cellpadding="1">
        <tr height="20">
          <td height="20" width="1" class="mtxt_black">&nbsp;</td>
          <td height="30" width="758" class="mtxt_black">供应商分类重置</td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td class="bg_line" height="2"></td>
  </tr>
</table>
<br>

<form name="form1" action="/A400110.do" method="post" enctype="multipart/form-data">
<input type='hidden' name='submittype' value=''>
<table width="95%" border="0" cellspacing="0" cellpadding="0" align="center">
    <tr> 
        <td> 
        <table class=bg_table id=tableId    cellspacing=1 cellpadding=0 style="padding-left:5;padding-right:5" width=100% align=center border=0>
                <tr class="bg_column" height=25> 
                        <td align="left">批量导入供应商(Excel文件路径)：                      
                          <input type='file'  class="kuang"  id='excelfile' size='50' name='excelfile' onchange="checkFile(this);">
                          <input type='button' class="kuang" id='importExcel'  name='importExcel' value='导入..' onclick="doUploadProviderBaseFile(this);">
               
                            <input type='button' class="kuang" name='manufacturedown' value='下载供应商分类重置模板' onclick="downmanufacture();">
                     
                        </td>
                </tr>
            </table>
            <br>
</form>


    
    <p align="center">  
        <input type="button"  width="58" height="24" class="kuang" onclick="javascript:window.close();" value="关闭"/>
    </p>
    <script type="text/javascript">
        function find(){
            var cid=document.form1.concentricityid.value;
            var rootURL = "<%=response.encodeURL(request.getContextPath()+"/A400318.do")%>?cid="+cid;
            var returnval=window.showModalDialog(encodeURI(rootURL),"","dialogWidth=950px,dialogHeight=600px");
            if(returnval!=null){
                var cat=returnval[0].split("%");
                for(var i=0;i<cat.length;i++){
                    var a=i+1;
                    var s="manuftype"+a;
                    var sn=document.getElementById(s);
                    if(i==1){
                        change1(cat[0]);
                    }
                    if(i==2){
                        change2(cat[1]);
                    }
                    sn.value=cat[i];
                }
                var name=returnval[1];
                document.form1.manufacturename.value=name;
                document.form1.unitprice.value=returnval[4];
                document.form1.quantunit.value=returnval[5];
                document.form1.manufacturetype.value=returnval[6];
                document.form1.manfuacturespec.value=returnval[7];
                document.form1.qualityassureperiod.value=returnval[8];
                document.form1.manufacturername.value=returnval[9];
                document.form1.makearea.value=returnval[10];
                document.form1.manufacturebrand.value=returnval[11];
                document.form1.drawingpiececode.value=returnval[12];
                document.form1.isbuy.value=returnval[13];
                document.form1.balancemode.value=returnval[14];
                document.form1.remark.value=returnval[16];
                var prope=returnval[15];
                var reg=";";
                var pro=new Array(6);
                if(prope!=null&&Trim(prope)!=""){
                    reg=prope.substring(prope.length-1,prope.length);
                    var str=prope.split(reg);
                    for (var tI = 0; tI < 6; tI++) {
                        var bl=1;
                        for(var a=0;a<str.length;a++)
                        {
                            var st=str[a].split("：");
                            if(st.length<=1){
                                st=str[a].split(":");
                            }
                            if(st[0]=="适用车型"){
                                document.form1.pro1.value=st[1];
                            }
                            if(st[0]=="适用机型"){
                                document.form1.machinetype.value=st[1];
                            }
                            if(st[0]=="适用底盘"){
                                document.form1.pro3.value=st[1];
                            }
                            if(st[0]=="级别特征"){
                               document.form1.pro4.value=st[1];
                            }
                            if(st[0]=="材质"){
                                document.form1.pro5.value=st[1];
                            }
                            if(st[0]=="其他属性"){
                                document.form1.pro6.value=st[1];
                            }
                        }
                    }
             }
             
            }
        }
        var request = false;
        function selectyes(a,b){
            a.value=Trim(a.value);
            if(Trim(a.value)==""){
                return false;
            }
            if(window.XMLHttpRequest) {  //非IE浏览器，用xmlhttprequest对象创建
                request=new XMLHttpRequest();
            } else if(window.ActiveXObject) { //IE浏览器用activexobject对象创建
                request=new ActiveXObject("Microsoft.XMLHttp");
            }
            
            if(request){
                var sid= Trim(a.value);
                var url = "<%=response.encodeURL(root+"/jsp/sysmaintain/manufactureAddCon.jsp")%>?conid=" + sid+"&ck="+b; 
                url=encodeURI(url);
                request.open("GET", encodeURI(url), true); 
                if(b=="1"){
                    request.onreadystatechange = updatePage; 
                }else if(b=="2"){
                    request.onreadystatechange = updatePage2;
                }
                request.send(null);
            }else{
                document.getElementById("conidyes").innerText="*";
            }
        }
        
        function updatePage(){
        var f=document.getElementById("conidyes");
        var p=document.getElementById("oldpid");
        var sign=document.getElementById("sign");
            if(request.readyState == 4){      //已完成
                if(request.status == 200){ 
                    var text = request.responseText;
                    if(text!=null&&Trim(text)!=""){
                        
                        sign.value="1";
                        var row=Trim(text).split("-");
                        f.innerHTML="<a href='javascript:void(0);' onclick='find();'>有 "+row[0]+" 条相同集中编码产品</a>";
                        if(row.length>1){
                            p.value=row[1];
                        }
                    }else{
                        f.innerText="*";
                        sign.value="0";
                        p.value="";
                    }
                }else 
                    f.innerText="*";
                    sign.value="0";
                }
        }
        function updatePage2(){
            var newproname=document.getElementById("provider_name");
            var newproid=document.getElementById("provider_id");
            if(request.readyState == 4){      //已完成
                if(request.status == 200){ 
                    var text = request.responseText;
                    if(text!=null&&Trim(text)!=""){
                        var t=Trim(text).split("%");
                        newproid.value=t[0];
                        newproname.value=t[1];
                    }else{
                        alert("该供应商不存在，重新输入或选择");
                    }
                }else 
                    f.innerText="*";
                }
        }
        function downmanufacture(){
        	   form1.action = "<%= response.encodeURL(request.getContextPath() + "/A400111.do") %>";
               form1.submit();
        }
        function viewmanufacture(){
            window.document.location.href="<%=response.encodeURL(request.getContextPath()+"/A400312.do")%>";
        }
    </script>
</body>
</html>